/**
 * @Title: TBUtils.java
 * @Package com.lemon.utils
 * @Description: (一句话阐述):
 * @author Ran_cc
 * @date 2018年5月19日
 * @version V1.0
 */
package com.lemon.utils.tb;

import java.io.IOException;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.Test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lemon.conf.MyException;
import com.lemon.utils.HttpUtil;
import com.lemon.utils.StringUtil;
import com.taobao.api.internal.util.WebUtils;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Company:
 * </p>
 * 
 * @author Ran_cc
 * @date 2018年5月19日
 * @版本 V 1.0
 */
/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Company:
 * </p>
 * 
 * @author Ran_cc
 * @date 2018年6月7日
 * @版本 V 1.0
 */
public class TBUtils {

	public static final String gw_api = "http://gw.api.taobao.com/router/rest ";
	public static final String appkey = "24898493";
	public static final String secret = "28a5fc594e9eba6d9e74752ad520d7ec";
	public static final String redirect_uri = "http://192.1.0.2:888/au/taoBaoOauth";
	public static final String redirect_url = "http://192.1.0.2:888/";
	/**
	 * <b>Description:<em><blockquote>
	 * 获得get的url返回信息<br>
	 * </blockquote></em></b>
	 * 
	 * @Title: getTbUrlDetil
	 * @return
	 * @author Ran_cc
	 * @date 2018年5月19日
	 */
	public static String tbHttpGet(String url) {
		org.apache.http.client.HttpClient client = HttpClients.createDefault();
		try {
			HttpGet get = new HttpGet(url);
			HttpResponse response;
			response = client.execute(get);
			HttpEntity entity = response.getEntity();
			String result = EntityUtils.toString(entity , "UTF-8");
			return result;
		} catch (ClientProtocolException e) {
			MyException.writeErr(e);
		} catch (IOException e) {
			MyException.writeErr(e);
		}
		return null;
	}

	/**
	 * <b>Description:<em><blockquote>
	 * 通过淘宝淘宝令文案里面的短地址获得商品id和详情地址<br>
	 * 例如:"http://m.tb.cn/h.Wz9RkrK";
	 * </blockquote></em></b>
	 * 
	 * @Title: getTbUrlDetil
	 * @return
	 * @author Ran_cc
	 * @date 2018年5月19日
	 */
	public static String getTbUrlDetilByShort(String url) {
		//先解析淘宝短连接地址内容,获取压缩的源地址
		org.apache.http.client.HttpClient client = HttpClients.createDefault();
		try {

			HttpGet get = new HttpGet(url);
			HttpResponse response;
			response = client.execute(get);
			HttpEntity entity = response.getEntity();
			String result = EntityUtils.toString(entity , "UTF-8");
			int indexOf = result.indexOf("https://s.click.taobao.com");
			String re2 = result.substring(indexOf , result.length());
			int re2Index = re2.indexOf("';");
			String res = re2.substring(0 , re2Index);
			//            System.out.println("=====:"+res);
			//将解析到的 源地址再次解析商品的详情地址
			return getTbUrlDetilByReduce(res);
		} catch (ClientProtocolException e) {
			//将错误信息输出到日志文件
			MyException.writeErr(e);
		} catch (IOException e) {
			//将错误信息输出到日志文件
			MyException.writeErr(e);
		}
		return null;
	}

	/**
	 * <b>Description:<em><blockquote>
	 * 通过淘宝压缩的地址获得商品详情连接<br>
	 * 链接:http://s.click.taobao.com/t?e=zGU34CA7K%2BPkqB07S4%2FK0CITy7klxxrJ35Nnc0ls8UNch6eorWAPrhuAvw2mQW2OJDeSwknfCSiKd622D%2BDnIc9QSYrG4navJ4t7sfX4ek43cWA%3D
	 * </blockquote></em></b>
	 * 
	 * @Title: getTbUrlDetilByReduce
	 * @param urlStr
	 * @return
	 * @author Ran_cc
	 * @date 2018年5月19日
	 */
	@SuppressWarnings("deprecation")
	public static String getTbUrlDetilByReduce(String urlStr) {

		String dd = "http://s.click.taobao.com/t?e=zGU34CA7K%2BPkqB07S4%2FK0CITy7klxxrJ35Nnc0ls"
				+ "8UNch6eorWAPrhuAvw2mQW2OJDeSwknfCSiKd622D%2BDnIc9QSYrG4navJ4t7sfX4ek43cWA%3D";
		HttpClient client;

		GetMethod get = null;
		try {
			client = new HttpClient(new MultiThreadedHttpConnectionManager());
			client.getHttpConnectionManager().getParams().setConnectionTimeout(10000);
			client.getParams().setParameter(HttpMethodParams.USER_AGENT ,
					"Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)");  //让服务器认为是IE  
			get = new GetMethod(urlStr);
			get.setFollowRedirects(false); //禁止自动重定向  
			int iGetResultCode = client.executeMethod(get);
			String _refer = get.getResponseHeader("location").getValue(); //打印地址 
			System.out.println("原地址:" + urlStr);
			System.out.println("解析后的地址_refer:" + _refer);
			Map<String , String> params = StringUtil.getUrlParams(_refer);
			if (params != null) {
				String iddd = params.get("id");
				if (StringUtil.isNotBlank(iddd)) {
					return _refer;
				} else if (_refer.indexOf("//s.click.taobao.com/t?e=") >= 0) {
					get = new GetMethod(urlStr);
					get.setFollowRedirects(false); //禁止自动重定向  
					int iGetResultCode4 = client.executeMethod(get);
					_refer = get.getResponseHeader("location").getValue(); //打印地址  
				}
			}
			GetMethod get2 = new GetMethod(URLDecoder.decode(_refer.split("tu=")[1]));
			get2.addRequestHeader("Referer" , _refer);
			get2.setFollowRedirects(false); //禁止自动重定向  
			int iGetResultCode2 = client.executeMethod(get2);
			String realUrl = get2.getResponseHeader("location").getValue(); //打印地址  
			System.out.println("REAL URL: " + realUrl);
			//			GetMethod get3 = new GetMethod(realUrl);
			//			int iGetResultCode3 = client.executeMethod(get3);
			//			String responseBody = get3.getResponseBodyAsString();
			/*
			 * System.out.println("Response Body: "+responseBody);
			 * System.out.println(responseBody.substring(responseBody.indexOf("sellerRate=" +
			 * "")+12,responseBody.indexOf("&", responseBody.indexOf("sellerRate="))));
			 * System.out.println("\n\n\n这是我想要的URL: "+realUrl);
			 */
			return realUrl;
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			get.releaseConnection();
		}
		return null;
	}

	@SuppressWarnings("deprecation")
	public static String getTbUrlDetilBySuperReduce(String urlStr) {

		String dd = "https://s.click.taobao.com/MtyfqNw";
		HttpClient client;

		GetMethod get = null;
		try {
			client = new HttpClient(new MultiThreadedHttpConnectionManager());
			client.getHttpConnectionManager().getParams().setConnectionTimeout(10000);
			client.getParams().setParameter(HttpMethodParams.USER_AGENT ,
					"Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)");  //让服务器认为是IE  
			get = new GetMethod(urlStr);
			get.setFollowRedirects(false); //禁止自动重定向  
			int iGetResultCode = client.executeMethod(get);
			String _refer = get.getResponseHeader("location").getValue(); //打印地址  
			Map<String , String> params = StringUtil.getUrlParams(_refer);
			if (params != null) {
				String iddd = params.get("id");
				if (StringUtil.isNotBlank(iddd)) {
					return _refer;
				}
			}
			GetMethod get2 = new GetMethod(URLDecoder.decode(_refer.split("tu=")[1]));
			get2.addRequestHeader("Referer" , _refer);
			get2.setFollowRedirects(false); //禁止自动重定向  
			int iGetResultCode2 = client.executeMethod(get2);
			String realUrl = get2.getResponseHeader("location").getValue(); //打印地址  
			System.out.println("REAL URL: " + realUrl);
			GetMethod get3 = new GetMethod(realUrl);
			int iGetResultCode3 = client.executeMethod(get3);
			String responseBody = get3.getResponseBodyAsString();
			/*
			 * System.out.println("Response Body: "+responseBody);
			 * System.out.println(responseBody.substring(responseBody.indexOf("sellerRate=" +
			 * "")+12,responseBody.indexOf("&", responseBody.indexOf("sellerRate="))));
			 * System.out.println("\n\n\n这是我想要的URL: "+realUrl);
			 */
			return realUrl;
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			get.releaseConnection();
		}
		return null;
	}

	/**
	 * <b>Description:<em><blockquote><br>
	 * 通过商品详情连接获得商品id
	 * </blockquote></em></b>
	 * 
	 * @Title: getTbItemId
	 * @return id 淘宝商品id
	 * @author Ran_cc
	 * @date 2018年5月19日
	 */
	public static String getTbItemId(String url) {
		Map<String , String> map = StringUtil.getUrlParams(url);
		String id = map.get("id");
		if (StringUtil.isEmpty(id)) {
			id = map.get("item_id");
		}
		if (StringUtil.isEmpty(id)) {
			map = StringUtil.getUrlParams(getTbUrlDetilByReduce(url));
			id = map.get("id");
			if (StringUtil.isEmpty(id)) {
				id = map.get("item_id");
			}
		}
		if (StringUtil.isEmpty(id)) {
			return null;
		}
		return id;

	}

	/**
	 * <b>Description:<em><blockquote>
	 * 通过淘口令指定字符获得淘宝长连接<br>
	 * 然后通过长连接获得淘宝商品的详情地址
	 * </blockquote></em></b>
	 * 
	 * @Title: getTbLongUrlByTKL
	 * @param tkl
	 * @return
	 * @author Ran_cc
	 * @date 2018年6月7日
	 */
	public static String getTbLongUrlByTKL(String tkl) {
		Map<String , String> map = new HashMap<String , String>();
		map.put("tkl" , tkl);
		String string = HttpUtil.doPost("http://api.chaozhi.hk/tb/tklParse" , map);
		JSONObject parse = (JSONObject) JSONObject.parse(string);
		JSONObject jsonObject = parse.getJSONObject("data");
		System.out.println(
				StringUtil.DateToString(new Date() , 41) + ": 逆向解析淘口令,获取商品链接地址:" + jsonObject.getString("url"));
		return jsonObject.getString("url");
	}

	@Test
	public void getItemInfoById() {
		try {
			/*
			 * TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest?", appkey, secret);
			 * TbkItemInfoGetRequest req = new TbkItemInfoGetRequest();
			 * req.setNumIids("123,456");
			 * req.setPlatform(1L);
			 * req.setIp("11.22.33.43");
			 * TbkItemInfoGetResponse rsp = client.execute(req);
			 * System.out.println(rsp.getBody());
			 */

			//taobao.tbk.item.info.get(淘宝客商品详情（简版）)
			Map<String , String> params = new HashMap<String , String>();
			params.put("method" , "taobao.tbk.item.info.get");
			params.put("app_key" , appkey);
			params.put("secret" , secret);
			params.put("timestamp" , new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
			params.put("v" , "2.0");
			params.put("format" , "json");
			params.put("sign_method" , "md5");
			params.put("buyer_ip" , "127.0.0.1");
			params.put("fields" ,
					"num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url");
			params.put("platform" , "1");
			params.put("num_iids" , "564752125517");

			String sign = SignUtil.signTopRequest(params , "" , "md5");
			System.out.println("sign----" + sign);
			params.put("sign" , sign);
			System.out.println("sign-----" + JSONObject.toJSONString(params));
			String result1 = HttpUtil.doPost("http://gw.api.taobao.com/router/rest" , params);
			System.out.println("result---------" + result1);

		} catch (Exception e) {
			//将错误信息输出到日志文件
			MyException.writeErr(e);
		}
	}

	/**
	 * <b>Description:<blockquote> 淘宝授权登陆 , 获得授权token以及信息
	 * </blockquote></b>
	 * 
	 * @Title: getAccessToken
	 * @param code
	 * @return 返回用户的基本信息和token信息
	 * @author Ran_cc
	 * @date 2018年6月23日
	 */
	public static JSONObject getAccessToken(String code) {
		String url = "https://oauth.taobao.com/token";
		Map<String , String> props = new HashMap<String , String>();
		props.put("grant_type" , "authorization_code");
		/* 测试时，需把test参数换成自己应用对应的值 */
		props.put("code" , code);
		props.put("client_id" , appkey);
		props.put("client_secret" , secret);
		props.put("redirect_uri" , redirect_url);
		props.put("view" , "web");
		String s = "";
		try {
			s = WebUtils.doPost(url , props , 30000 , 30000);
			System.out.println(s);

			JSONObject parse = (JSONObject) JSONObject.parse(s);
			String object = parse.get("access_token").toString();
			System.out.println("accessToken:" + object);
			//后10位是淘宝用户的userid
			System.out.println("tb_user_id:" + object.substring(object.length() - 10 , object.length()));
			return parse;
		} catch (IOException e) {
			MyException.writeErr(e , "淘宝授权登陆失败");
		}
		return null;
	}

	/**
	 * <b>Description:<blockquote> 淘宝授权登陆 , 获得授权token以及信息
	 * </blockquote></b>
	 * 
	 * @Title: getAccessToken
	 * @param code
	 * @return 返回用户的基本信息和token信息
	 * @author Ran_cc
	 * @date 2018年6月23日
	 */
	public static JSONObject getAccessTokenWap(String code) {
		String url = "https://oauth.taobao.com/token";
		Map<String , String> props = new HashMap<String , String>();
		props.put("grant_type" , "authorization_code");
		/* 测试时，需把test参数换成自己应用对应的值 */
		props.put("code" , code);
		props.put("client_id" , appkey);
		props.put("client_secret" , secret);
		props.put("redirect_uri" , redirect_url);
		props.put("view" , "wap");
		String s = "";
		try {
			s = WebUtils.doPost(url , props , 30000 , 30000);
			System.out.println(s);

			JSONObject parse = (JSONObject) JSONObject.parse(s);
			String object = parse.get("access_token").toString();
			System.out.println("accessToken:" + object);
			//后10位是淘宝用户的userid
			System.out.println("tb_user_id:" + object.substring(object.length() - 10 , object.length()));
			return parse;
		} catch (IOException e) {
			MyException.writeErr(e , "淘宝授权登陆失败");
		}
		return null;
	}

	/**
	 * 返回单个字符串，若匹配到多个的话就返回第一个 , 包含匹配关键词返回
	 * 
	 * @param soap
	 * @param rgex
	 * @return 包含匹配关键词返回
	 */
	public static String getTKLbYinfo(String tkl) {
		String rgex = "€(.*?)€";
		Pattern pattern = Pattern.compile(rgex);// 匹配的模式  
		Matcher m = pattern.matcher(tkl);
		String mm = "";
		while (m.find()) {
			mm = m.group();
		}
		if (StringUtil.isEmpty(mm)) {
			pattern = Pattern.compile("￥(.*?)￥");// 匹配的模式  
			m = pattern.matcher(tkl);
			while (m.find()) {
				mm = m.group();
			}
		}
		return mm;
	}

	/**
	 * <b>Description:<blockquote> 通过商品链接获得淘口令
	 * </blockquote></b>
	 * 
	 * @Title: getTKLByUrl
	 * @param url
	 * @param type 1=淘宝连接 0=淘宝客连接(带有pid的推广位)
	 * @return
	 * @author Ran_cc
	 * @date 2018年8月10日
	 */
	public static String getTKLByUrl(String url , String pic , String title , int type) {

		Map<String , String> map = new HashMap<String , String>();
		map.put("link" , url);
		map.put("image" , pic);
		map.put("text" , title);
		if (type == 0) {
			map.put("type" , "B");
		} else if (type == 1) {
			map.put("type" , "A");
		} else {
			return null;
		}
		map.put("link" , url);
		String string = HttpUtil.doPost("http://api.chaozhi.hk/tb/linkTkl" , map);
		System.out.println(": 通过连接地址生成淘口令:" + string);
		JSONObject parse = (JSONObject) JSONObject.parse(string);
		if (parse == null) {
			return null;
		}
		JSONObject jsonObject = parse.getJSONObject("data");
		//		System.out.println(StringUtil.DateToString(new Date() , 41) + ": 通过连接地址生成淘口令:" + jsonObject.getString("tkl"));
		return jsonObject.getString("tkl");

	}

	/**
	 * <b>Description:<blockquote> 通过淘宝宝网址生成短连接
	 * </blockquote></b>
	 * 
	 * @Title: getTbShortLinkByTBB
	 * @param url
	 * @return
	 * @author Ran_cc
	 * @date 2018年8月10日
	 */
	public static String getTbShortLinkByTBB(String url) {
		//		System.out.println("需要生成短连接地址:" + url);
		Map<String , String> map = new HashMap<String , String>();
		map.put("url" , url);
		String string = HttpUtil.doPost("http://tao.bb/api/Create" , JSON.toJSONString(map));
		//		String string = HttpUtil.doPost("http://dwz.cn/admin/create" , JSON.toJSONString(map));
		JSONObject parse = (JSONObject) JSONObject.parse(string);
		if (parse == null) {
			return null;
		}
		//		System.out.println(StringUtil.DateToString(new Date() , 41) + ": 通过DWZ生成短链:" + string);
		System.out.println(StringUtil.DateToString(new Date() , 41) + ": 通过TBB生成短链:" + string);
		//		return parse.getString("ShortUrl");
		return "http://tao.bb/" + parse.getString("key");
	}

	public static void main(String[] args) {
		// System.out.println(getTbItemId("https://item.taobao.com/item.htm?id=566155525244&ali_trackid=2:mm_127654593_41018138_167788871:1526735410_359_1230627685&spm=a21wq.8595780.1000.2&scm=20140618.1.01010001.s101c6"));
		//getItemInfoById("545229122567");
		// tbHttpGet("https://uland.taobao.com/cp/pc_coupon_list?pid=mm_127654593_41018138_167788871&queryCount=20&page=0&pageSize=20&channel=couponlist_shumajiadian");

		/*
		 * String string = getTbLongUrlByTKL("￥hVYjb1L0kzi￥");
		 * System.out.println(string);
		 */
		
		
		/*
		 * String url =
		 * "http://s.click.taobao.com/t?e=m%3D2%26s%3DVueNvaSEKItw4vFB6t2Z2ueEDrYVVa64RZKDdhY4Y8E%2F7U6WWca0EKkY2j%2Bnx091BReyEv7GSVZZSDZvDivPY2z9CsjPshpph36SwbBTjn4NBpDLf5mzbaKPMAe%2BPPJt50KccpzyHeadTsjS8asKjc9ww2XuhO8v8nJpceDhprOR4ypTBJBwtOAjBDXvuqoU47FHjfsActlORznNxnkJI9nFEMkYTPPXcWgY0kHQjzNcZwNNaIFAm6oXdRVk0YD9y4dl%2Bx9N66IyTHvoY3%2BoyCKLig7pG41owheVFHhoPgwZ0lfj9x6ZZLrzCKN3GNZPcSpj5qSCmbA%3D&scm=1007.15348.106728.0_4083&pvid=64019fcf-bbf7-40eb-813d-ab01e20a7591&app_pvid=0bb6258215341396030667384edce5&ptl=floorId:4083;pvid:64019fcf-bbf7-40eb-813d-ab01e20a7591;app_pvid:0bb6258215341396030667384edce5&union_lens=lensId:0b0863c0_090b_16531d89986_ab71";
		 * String pic = "http://img.alicdn.com/bao/uploaded/i1/3695417847/TB1GhHfHNGYBuNjy0FnXXX5lpXa_!!0-item_pic.jpg";
		 * String titl = "彩虹口袋零食大礼包网红组合整箱超大混装一箱女生日抖音实惠小吃";
		 * String string = getTKLByUrl(url , pic , titl , 1);
		 * System.out.println(string);
		 */

		String url = "https://uland.taobao.com/coupon/edetail?e=kz0FpYIL%2BloN%2BoQUE6FNzGee%2Fwm7K5M8%2FhN0LU%2Fs1qDcdPbalCouzdKALChz%2Bmr6urp45eNl2toHTeXNDeVFEnz%2F5lYwoL5IC0DytI6FkgSuppFdR3hDs5PlBV30pW223PSjRR%2Ft9U%2BKkm4gzJDYRBFI3pIRmPrc&af=1&pid=mm_127654593_41018138_167788871";
		System.out.println(getTbShortLinkByTBB(url));

		//////////////////////////////////////////////////////////////////////////////
		/*
		 * String q = "【背心女夏打底低胸衣服显胸上衣外穿夏季紧身性感女装短款吊带衫】，復·制这段描述￥IFRFbbjPtOB￥后到淘♂寳♀";
		 * String string = getTKLbYinfo(q);
		 * System.out.println(string);
		 */
		////////////////////////////////////////////////////////////////////////////

		//		String q = "https://s.click.taobao.com/MtyfqNw";
//		String q = "http://s.click.taobao.com/t?e=m%3D2%26s%3DVueNvaSEKItw4vFB6t2Z2ueEDrYVVa64RZKDdhY4Y8E%2F7U6WWca0EKkY2j%2Bnx091BReyEv7GSVZZSDZvDivPY2z9CsjPshpph36SwbBTjn4NBpDLf5mzbaKPMAe%2BPPJt50KccpzyHeadTsjS8asKjc9ww2XuhO8v8nJpceDhprOR4ypTBJBwtOAjBDXvuqoU47FHjfsActlORznNxnkJI9nFEMkYTPPXcWgY0kHQjzNcZwNNaIFAm6oXdRVk0YD9y4dl%2Bx9N66IyTHvoY3%2BoyCKLig7pG41owheVFHhoPgwZ0lfj9x6ZZLrzCKN3GNZPcSpj5qSCmbA%3D&scm=1007.15348.106728.0_4083&pvid=64019fcf-bbf7-40eb-813d-ab01e20a7591&app_pvid=0bb6258215341396030667384edce5&ptl=floorId:4083;pvid:64019fcf-bbf7-40eb-813d-ab01e20a7591;app_pvid:0bb6258215341396030667384edce5&union_lens=lensId:0b0863c0_090b_16531d89986_ab71"
		//				+ "";
		//		String q = "https://s.click.taobao.com/t?e=m%3D2%26s%3DZ9M%2F0YM77U4cQipKwQzePOeEDrYVVa64K7Vc7tFgwiHjf2vlNIV67o9ty1MiCkmssUZsiWgXrvg5ta2oeBpIfjDzdmH0FW60F5RN%2BXdU0u4NgknnwwM7jFxVs1dgo8e%2FZ92YJG2Ho5Id0fniY6dvNRKQDTqPZV%2BS2bz7gz0HmJE%3D";
		//		String q = "http://s.click.taobao.com/t?e=m%3D2%26s%3DNwKa9CqFoshw4vFB6t2Z2ueEDrYVVa64RZKDdhY4Y8E%2F7U6WWca0EKkY2j%2Bnx091BReyEv7GSVZZSDZvDivPY2z9CsjPshpph36SwbBTjn4NBpDLf5mzbUsnMSkSkRQSs%2FLO%2FPuaVbYSIz%2BVIb9tlAI53ocqudyVWhCm3OhCGNrO54LQ%2FVw1L7SqdkxH6LRFnaYpFBIfC%2F0elwne0cbG4gSa6ynmwq5aR%2F07OeGkOBraXMBGOGlf%2Fifp%2BdSA2Th7G57rnoRkX4Ni3cxBbJThHgI53ocqudyV0sVEWRtsQ7qbP89%2Faylf1UNrdzg76HDRQbDoFkw1Rb4%3D&scm=1007.15348.106728.0_4083&pvid=64019fcf-bbf7-40eb-813d-ab01e20a7591&app_pvid=0bb6258215341396030667384edce5&ptl=floorId:4083;pvid:64019fcf-bbf7-40eb-813d-ab01e20a7591;app_pvid:0bb6258215341396030667384edce5&union_lens=lensId:0b0863c0_090b_16531d89c21_ae76";
		//		String string = getTbUrlDetilByReduce(q);
		//		System.out.println(string);

		////////////////////////////////////////////////////////////////////////////
		// String string = HttpUtil.doGet("https://item.taobao.com/item.htm?id=567447765208", null);
		/*
		 * String string = tbHttpGet("https://item.taobao.com/item.htm?id=567447765208");
		 * long time1 = new Date().getTime();
		 * System.out.println(time1);
		 * String ss =
		 * "<li  class=\"tb-selected\" ><div class=\"tb-pic tb-s50\"><a href=\"#\"><img data-src=\"//gd3.alicdn.com/imgextra/i1/392243499/TB2eqM1ngaTBuNjSszfXXXgfpXa_!!392243499.jpg_50x50.jpg\" /></a>"
		 * + "</div></li>";
		 * ss += "<div class=\"tb-pic tb-s50\">"
		 * + "<a href=\"#\"><img data-src=\"//gd4.alicdn.com/imgextra/i4/392243499/TB2wY8DnuOSBuNjy0FdXXbDnVXa_!!392243499.jpg_50x50.jpg\" /></a>"
		 * + "</div> </li><li >"
		 * + "     <div class=\"tb-pic tb-s50\">"
		 * + "         <a href=\"#\"><img data-src=\"//gd2.alicdn.com/imgextra/i2/392243499/TB2meMFe_XYBeNkHFrdXXciuVXa_!!392243499.jpg_50x50.jpg\" /></a>"
		 * + "     </div></li><li >"
		 * + "     <div class=\"tb-pic tb-s50\">"
		 * + "         <a href=\"#\"><img data-src=\"//gd4.alicdn.com/imgextra/i4/392243499/TB27CKcnx9YBuNjy0FfXXXIsVXa_!!392243499.jpg_50x50.jpg\" /></a>"
		 * + "     </div></li><li ><div class=\"tb-pic tb-s50\">"
		 * + "         <a href=\"#\"><img data-src=\"//gd4.alicdn.com/imgextra/i4/392243499/TB2bl1anqmWBuNjy1XaXXXCbXXa_!!392243499.jpg_50x50.jpg\" /></a>"
		 * + "     </div> </li>";
		 * List<String> list = new ArrayList<String>();
		 * Pattern p_img = Pattern.compile("<a\\shref=\"#\"><(img|IMG)(.*?)(src|SRC)=(\"|\')(.*?)(\"|\')");
		 * Matcher m_img = p_img.matcher(string);
		 * boolean result_img = m_img.find();
		 * if ( result_img ) {
		 * while(result_img) {
		 * // 获取到匹配的<img />标签中的内容
		 * String str_img = m_img.group(5);
		 * System.out.println("http:" + str_img);
		 * // 开始匹配<img />标签中的src
		 * // Pattern p_src = Pattern.compile("(src|SRC)=(\"|\')(.*?)(\"|\')");
		 * // Matcher m_src = p_src.matcher(str_img);
		 * // if ( m_src.find() ) {
		 * // String str_src = m_src.group(3);
		 * // list.add(str_src);
		 * // }
		 * // 匹配content中是否存在下一个<img />标签，有则继续以上步骤匹配<img />标签中的src
		 * result_img = m_img.find();
		 * }
		 * }
		 * for(int i = 0; i < list.size(); i++) {
		 * System.out.println("http:" + list.get(i));
		 * }
		 * long time2 = new Date().getTime();
		 * System.out.println(time2 - time1);
		 * // <img id="J_ImgBooth" src="//gd2.alicdn.com/imgextra/i1/392243499/TB2eqM1ngaTBuNjSszfXXXgfpXa_!!392243499.jpg_400x400.jpg" data-hasZoom="700" data-size="400x400"/>
		 * try {
		 * Pattern p_img2 = Pattern.compile("<(img|IMG)\\sid=\"J_ImgBooth\"\\s(src|SRC)=(\"|\')(.*?)(\"|\')");
		 * Matcher m_img2 = p_img2.matcher(string);
		 * boolean result_img2 = m_img2.find();
		 * if ( result_img2 ) {
		 * while(result_img2) {
		 * System.out.println(m_img2.group(4));
		 * result_img2 = m_img2.find();
		 * }
		 * }
		 * long time3 = new Date().getTime();
		 * System.out.println("time:" + (time3 - time2));
		 * } catch (Exception e) {
		 * e.printStackTrace();
		 * }
		 */
		////////////////////////////////////////////////////////////////////////////////////////
	}

}
